Passed
Push — master ( d1a202...380a8f )
by Barry
01:01
created

test.js ➔ describe(ꞌmdprepare test filesꞌ)   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 37
rs 8.8571
c 1
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test.js ➔ ... ➔ it 0 8 1
A test.js ➔ ... ➔ it(ꞌtest working with read only file - should errorꞌ) 0 10 1
1
/* global describe, it */
2
3
 const processFile = require('../dist/processFile.js').default
4
 const {processText} = require('../dist/processFile.js')
5
 const {findCode, findMdpInsert, findMdpCode} = require('../dist/helpers.js')
6
 const {runCliCmd} = require('../dist/processFile.js')
7
 const assert = require('assert')
8
 const {exec} = require('child_process')
9
 const fs = require('fs-extra')
10
 const os = require('os')
11
12
 const mdpLinkTests = [
13
   {name: 'Simple 1', text: '[>]: # (mdpInsert abc)\r\n12345\r\n[<]: #\r\n', result: {start: 0, length: 37, internalStart: 24, internalLength: 5, commandString: 'mdpInsert abc'}},
14
   {name: 'Simple 2', text: 't\n[> a]: # (mdpInsert abc)\r\n12345\r\n[< b]: #\r\n', result: {start: 2, length: 41, internalStart: 28, internalLength: 5, commandString: 'mdpInsert abc'}},
15
   {name: 'Simple 3', text: '[>]: # (mdpInsert a)\r\n[<]: #\r\n', result: {start: 0, length: 28, internalStart: 22, internalLength: -2, commandString: 'mdpInsert a'}},
16
   {name: 'Simple 4', text: '[>]: # (mdpInsert abc)\r\n12345\r\n[<]: #', result: {start: 0, length: 37, internalStart: 24, internalLength: 5, commandString: 'mdpInsert abc'}},
17
   {name: 'Simple 5 (invalid)', text: '[#]: # (mdpInsert abc)\r\n12345\r\n[<]: #\r\n', result: {start: -1}},
18
   {name: 'code fenced', text: '[>]: # (mdpInsert abc)\r\n12345\r\n`[<]`: #\r\n', result: {start: -1}},
19
   {name: 'embedded', text: '[>]: # (mdpInsert abc)\r\n12\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[<]: #\r\n345\r\n[<]: #\r\n', result: {start: 0, length: 76, internalStart: 24, internalLength: 44, commandString: 'mdpInsert abc'}},
20
   {name: 'embedded, 5 deep', text: '[>]: # (mdpInsert abc)\r\n12\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[<]: #\r\n\r\n[<]: #\r\n\r\n[<]: #\r\n\r\n[<]: #\r\n345\r\n[<]: #\r\n', result: {start: 0, length: 193, internalStart: 24, internalLength: 161, commandString: 'mdpInsert abc'}},
21
   {name: 'embedded, too deep (6) - fails', text: '[>]: # (mdpInsert abc)\r\n12\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[<]: #\r\n\r\n[<]: #\r\n\r\n[<]: #\r\n\r\n[<]: #\r\n\r\n[<]: #\r\n345\r\n[<]: #\r\n', result: {start: -1}},
22
   {name: 'embedded, some fenced 1', text: '[>]: # (mdpInsert abc)\r\n12\r\n```\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n```\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[<]: #\r\n\r\n```\r\n[<]: #\r\n```\r\n[<]: #\r\n\r\n[<]: #\r\n\r\n[<]: #\r\n345\r\n[<]: #\r\n', result: {start: 0, length: 250, internalStart: 24, internalLength: 218, commandString: 'mdpInsert abc'}},
23
   {name: 'embedded, some fenced 2', text: '[>]: # (mdpInsert abc)\r\n12\r\n```\r\n[<]: #\r\n```\r\n[<]: #\r\n[<]: #\r\n', result: {start: 0, length: 52, internalStart: 24, internalLength: 20, commandString: 'mdpInsert abc'}},
24
   {name: 'embedded with following', text: '[>]: # (mdpInsert abc)\r\n12\r\n[>]: # (mdpInsert xyz)\r\nxyz\r\n[<]: #\r\n345\r\n[<]: #\r\n[>]: # (mdpInsert xyz)\r\n', result: {start: 0, length: 76, internalStart: 24, internalLength: 44, commandString: 'mdpInsert abc'}}
25
 ]
26
27
 const mdpCodeTests = [
28
   {name: 'Simple 1', text: '```json mdpInsert cat e.txt\r\ncode\r\n```', result: {start: 0, length: 38, internalStart: 29, internalLength: 4, commandString: 'json mdpInsert cat e.txt'}},
29
   {name: 'Fails mdpinsert spelt wrong', text: '```json mdpinsert cat e.txt\r\ncode\r\n```', result: {start: -1}},
30
   {name: 'Complex command line', text: 'text\r\n``` json   notes  mdpInsert cat e.txt --option1 sp --option2 \r\ncode\r\n```\r\n', result: {start: 6, length: 72, internalStart: 69, internalLength: 4, commandString: 'json   notes  mdpInsert cat e.txt --option1 sp --option2'}}
31
 ]
32
33
 const fencedCodeTests = [
34
   {name: 'Simple 1', text: 'plain\r\n```\r\ncode\r\n```\r\nplain', result: {start: 7, length: 14, internalStart: 12, internalLength: 4, commandString: ''}},
35
   {name: 'Simple 2', text: 'plain\n```\ncode\n```\nplain', result: {start: 6, length: 12, internalStart: 10, internalLength: 4, commandString: ''}},
36
   {name: 'Example 88', text: '```\n<\n >\n```', result: {start: 0, length: 12, internalStart: 4, internalLength: 4, commandString: ''}},
37
   {name: 'Example 89', text: '~~~\n<\n >\n~~~', result: {start: 0, length: 12, internalStart: 4, internalLength: 4, commandString: ''}},
38
   {name: 'Example 90', text: '``\nfoo\n``', result: {start: 0, length: 9, internalStart: 2, internalLength: 5, commandString: ''}},
39
   {name: 'Example 91', text: '```\naaa\n~~~\n```', result: {start: 0, length: 15, internalStart: 4, internalLength: 7, commandString: ''}},
40
   {name: 'Example 92', text: '~~~\naaa\n```\n~~~', result: {start: 0, length: 15, internalStart: 4, internalLength: 7, commandString: ''}},
41
   {name: 'Example 93', text: '````\naaa\n```\n``````', result: {start: 0, length: 19, internalStart: 5, internalLength: 7, commandString: ''}},
42
   {name: 'Example 94', text: '~~~~\naaa\n~~~\n~~~~', result: {start: 0, length: 17, internalStart: 5, internalLength: 7, commandString: ''}},
43
   {name: 'Example 95', text: '```', result: {start: 0, length: 3, internalStart: 3, internalLength: 0, commandString: ''}},
44
   {name: 'Example 96', text: '`````\n\n```\naaa', result: {start: 0, length: 14, internalStart: 6, internalLength: 8, commandString: ''}},
45
   {name: 'Example 97', text: '> ```\n> aaa\n\nbbb', result: {start: 0, length: 11, internalStart: 6, internalLength: 5, commandString: ''}},
46
   {name: 'Example 97a', text: '> ```\n> aaa\n> \n> bbb', result: {start: 0, length: 20, internalStart: 6, internalLength: 14, commandString: ''}},
47
   {name: 'Example 97b', text: '> ```\r\n> aaa\r\n\r\nbbb', result: {start: 0, length: 12, internalStart: 7, internalLength: 5, commandString: ''}},
48
   {name: 'Example 97c', text: '> ```\r\n> aaa\r\n> \r\n> bbb', result: {start: 0, length: 23, internalStart: 7, internalLength: 16, commandString: ''}},
49
   {name: 'Example 97d', text: '>```a\r\n>\r\nbbb', result: {start: 0, length: 8, internalStart: 7, internalLength: 1, commandString: 'a'}},
50
   {name: 'Example 98', text: '```\n\n  ```', result: {start: 0, length: 10, internalStart: 4, internalLength: 0, commandString: ''}},
51
   {name: 'Example 99', text: '```\n```', result: {start: 0, length: 7, internalStart: 4, internalLength: -1, commandString: ''}},
52
   {name: 'Example 100', text: ' ```\n aaa\naaa\n```', result: {start: 0, length: 17, internalStart: 5, internalLength: 8, commandString: ''}},
53
   {name: 'Example 101', text: '  ```\naaa\n  aaa\naaa\n  ```', result: {start: 0, length: 25, internalStart: 6, internalLength: 13, commandString: ''}},
54
   {name: 'Example 101b', text: '  ```\naaa\n  aaa\naaa\n  ```\r\n', result: {start: 0, length: 25, internalStart: 6, internalLength: 13, commandString: ''}},
55
   {name: 'Example 101c', text: '  ```\naaa\n  aaa\naaa\n  ```\n', result: {start: 0, length: 25, internalStart: 6, internalLength: 13, commandString: ''}},
56
   {name: 'Example 101d', text: '\r\n  ```\naaa\n  aaa\naaa\n  ```\r\n', result: {start: 2, length: 25, internalStart: 8, internalLength: 13, commandString: ''}},
57
   {name: 'Example 101e', text: '\n  ```\naaa\n  aaa\naaa\n  ```\r\n', result: {start: 1, length: 25, internalStart: 7, internalLength: 13, commandString: ''}},
58
   {name: 'Example 102', text: '   ```\n   aaa\n    aaa\n   ```', result: {start: 0, length: 28, internalStart: 7, internalLength: 14, commandString: ''}},
59
   {name: 'Example 103', text: '    ```\n    aaa\n    ```', result: {start: 0, length: 23, internalStart: 0, internalLength: 23, commandString: ''}},
60
   {name: 'Example 104', text: '```\naaa\n  ```', result: {start: 0, length: 13, internalStart: 4, internalLength: 3, commandString: ''}},
61
   {name: 'Example 105', text: '   ```\naaa\n  ```', result: {start: 0, length: 16, internalStart: 7, internalLength: 3, commandString: ''}},
62
   {name: 'Example 106', text: '```\naaa\n    ```', result: {start: 0, length: 15, internalStart: 4, internalLength: 11, commandString: ''}},
63
   {name: 'Example 107', text: '``` ```\naaa', result: {start: 0, length: 7, internalStart: 3, internalLength: 1, commandString: ''}},
64
   {name: 'Example 108', text: '~~~~~~\naaa\n~~~ ~~', result: {start: 0, length: 17, internalStart: 7, internalLength: 10, commandString: ''}},
65
   {name: 'Example 109', text: 'foo\n```\nbar\n```\nbaz', result: {start: 4, length: 11, internalStart: 8, internalLength: 3, commandString: ''}},
66
   {name: 'Example 110', text: 'foo\n---\n~~~\nbar\n~~~\n# baz', result: {start: 8, length: 11, internalStart: 12, internalLength: 3, commandString: ''}},
67
   {name: 'Example 111', text: '```ruby\ndef foo(x)\n  return 3\nend\n```', result: {start: 0, length: 37, internalStart: 8, internalLength: 25, commandString: 'ruby'}},
68
   {name: 'Example 112', text: '~~~~    ruby startline=3 $%@#$\r\ndef foo(x)\r\n  return 3\r\nend\r\n~~~~~~~', result: {start: 0, length: 68, internalStart: 32, internalLength: 27, commandString: 'ruby startline=3 $%@#$'}},
69
   {name: 'Example 113', text: '````;\r\n````', result: {start: 0, length: 11, internalStart: 7, internalLength: -2, commandString: ';'}},
70
   {name: 'Example 114', text: '``` aa ```\r\nfoo', result: {start: 0, length: 10, internalStart: 3, internalLength: 4, commandString: ''}},
71
   {name: 'Example 115', text: '```\r\n``` aaa\r\n```', result: {start: 0, length: 17, internalStart: 5, internalLength: 7, commandString: ''}},
72
   {name: 'Example 324', text: '`foo`', result: {start: 0, length: 5, internalStart: 1, internalLength: 3, commandString: ''}},
73
   {name: 'Example 325', text: '`` foo ` bar  ``', result: {start: 0, length: 16, internalStart: 2, internalLength: 12, commandString: ''}},
74
   {name: 'Example 326', text: '` `` `', result: {start: 0, length: 6, internalStart: 1, internalLength: 4, commandString: ''}},
75
   {name: 'Example 327', text: '``\r\nfoo\r\n``', result: {start: 0, length: 11, internalStart: 2, internalLength: 7, commandString: ''}},
76
   {name: 'Example 328', text: '`foo   bar\r\n  baz`', result: {start: 0, length: 18, internalStart: 1, internalLength: 16, commandString: ''}},
77
   {name: 'Example 329', text: '`a b`', result: {start: 0, length: 5, internalStart: 1, internalLength: 3, commandString: ''}},
78
   {name: 'Example 330', text: '`foo `` bar`', result: {start: 0, length: 12, internalStart: 1, internalLength: 10, commandString: ''}},
79
   {name: 'Example 331', text: '`foo\\`bar`', result: {start: 0, length: 6, internalStart: 1, internalLength: 4, commandString: ''}},
80
   {name: 'Example 332', text: '*foo`*`', result: {start: 4, length: 3, internalStart: 5, internalLength: 1, commandString: ''}},
81
   {name: 'Example 333', text: '[not a `link](/foo`)', result: {start: 7, length: 12, internalStart: 8, internalLength: 10, commandString: ''}},
82
   {name: 'Example 334', text: '`<a href="`">`', result: {start: 0, length: 11, internalStart: 1, internalLength: 9, commandString: ''}},
83
   {name: 'Example 336', text: '`<http://foo.bar.`baz>`', result: {start: 0, length: 18, internalStart: 1, internalLength: 16, commandString: ''}},
84
   {name: 'Example 338', text: '```foo``', result: {start: -1}},
85
   {name: 'Example 339', text: '`foo', result: {start: -1}},
86
   {name: 'Example 340', text: '`foo``bar``', result: {start: 4, length: 7, internalStart: 6, internalLength: 3, commandString: ''}},
87
   {name: 'block and code 1', text: '>```\r\n>code\r\ntext', result: {start: 0, length: 11, internalStart: 6, internalLength: 5, commandString: ''}},
88
   {name: 'block and code 1b', text: '>```\r\n>code\ntext', result: {start: 0, length: 11, internalStart: 6, internalLength: 5, commandString: ''}},
89
   {name: 'block and code 2', text: '>```\r\n>code\r\ntext```\r\n', result: {start: 0, length: 11, internalStart: 6, internalLength: 5, commandString: ''}},
90
   {name: 'block and code 3', text: '>```\r\n>code\r\n>```\r\ntext', result: {start: 0, length: 17, internalStart: 6, internalLength: 5, commandString: ''}}
91
 ]
92
93
 const processTextTests = [
94
   {
95
     name: 'Simple 1',
96
     text: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
97
     clear: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n',
98
     full_win: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n',
99
     full_linux: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n'
100
   }, {
101
     name: 'mdpInsert command not present',
102
     text: '[>]: # (mdpinsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
103
     clear: '[>]: # (mdpinsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
104
     full_win: '[>]: # (mdpinsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
105
     full_linux: '[>]: # (mdpinsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n'
106
   }, {
107
     name: 'Command Line invalid',
108
     text: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
109
     clear: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\n[<]: #\r\n',
110
     full_win: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\nERROR: Command failed: catt test/docs/abc.txt\n\'catt\' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n\r\n[<]: #\r\n',
111
     full_linux: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\nERROR: Command failed: catt test/docs/abc.txt\n/bin/sh: 1: catt: not found\n\r\n[<]: #\r\n'
112
   }, {
113
     name: 'Surrounded',
114
     text: '# Simple Test\r\nSome initial text.\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nold text\r\n[<]: #\r\nOther text',
115
     clear: '# Simple Test\r\nSome initial text.\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\nOther text',
116
     full_win: '# Simple Test\r\nSome initial text.\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\nOther text',
117
     full_linux: '# Simple Test\r\nSome initial text.\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\nOther text'
118
   }, {
119
     name: 'Empty',
120
     text: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n\r\n[<]: #\r\n',
121
     clear: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n',
122
     full_win: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n',
123
     full_linux: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n'
124
   }, {
125
     name: 'Blank Line',
126
     text: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n',
127
     clear: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n',
128
     full_linux: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n',
129
     full_win: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n'
130
   }, {
131
     name: 'LF only',
132
     text: '[>]: # (mdpInsert cat test/docs/abc.txt)\n[<]: #\n',
133
     clear: '[>]: # (mdpInsert cat test/docs/abc.txt)\n[<]: #\n',
134
     full_win: '[>]: # (mdpInsert cat test/docs/abc.txt)\nabc\n[<]: #\n',
135
     full_linux: '[>]: # (mdpInsert cat test/docs/abc.txt)\nabc\n[<]: #\n'
136
   }, {
137
     name: 'Two replacements',
138
     text: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
139
     clear: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n',
140
     full_win: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n',
141
     full_linux: '[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n'
142
   }, {
143
     name: 'Code Fence 1',
144
     text: '```json mdpInsert cat test/docs/abc.txt\r\nxyz\r\ncode\r\n```',
145
     clear: '```json mdpInsert cat test/docs/abc.txt\r\n```',
146
     full_win: '```json mdpInsert cat test/docs/abc.txt\r\nabc\r\n```',
147
     full_linux: '```json mdpInsert cat test/docs/abc.txt\r\nabc\r\n```'
148
   }, {
149
     name: 'Code Fence 2',
150
     text: 'ss\r\n```json mdpInsert cat test/docs/abc.txt\r\n```',
151
     clear: 'ss\r\n```json mdpInsert cat test/docs/abc.txt\r\n```',
152
     full_win: 'ss\r\n```json mdpInsert cat test/docs/abc.txt\r\nabc\r\n```',
153
     full_linux: 'ss\r\n```json mdpInsert cat test/docs/abc.txt\r\nabc\r\n```'
154
   }, {
155
     name: 'Code Fence and link',
156
     text: '```json mdpInsert cat test/docs/abc.txt\r\nxyz\r\ncode\r\n```\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
157
     clear: '```json mdpInsert cat test/docs/abc.txt\r\n```\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\n[<]: #\r\n',
158
     full_win: '```json mdpInsert cat test/docs/abc.txt\r\nabc\r\n```\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n',
159
     full_linux: '```json mdpInsert cat test/docs/abc.txt\r\nabc\r\n```\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nabc\r\n[<]: #\r\n'
160
   }, {
161
     name: 'Missing File',
162
     text: '[>]: # (mdpInsert cat file/not/present.txt)\r\n12345\r\n[<]: #\r\n',
163
     clear: '[>]: # (mdpInsert cat file/not/present.txt)\r\n[<]: #\r\n',
164
     full_win: '[>]: # (mdpInsert cat file/not/present.txt)\r\nERROR: Command failed: type file\\not\\present.txt\nThe system cannot find the path specified.\r\n\r\n[<]: #\r\n',
165
     full_linux: '[>]: # (mdpInsert cat file/not/present.txt)\r\nERROR: Command failed: cat file/not/present.txt\ncat: file/not/present.txt: No such file or directory\n\r\n[<]: #\r\n'
166
   }
167
 ]
168
169
// describe('mdprepare', function () {
170
//   it('fires and returns "processed x files message"', function (done) {
171
//     this.timeout(4000)
172
//     let buf = execSync('mdprepare --ignore **/*.js')
173
//     assert.equal(buf.toString().substr(0, 10), 'processed ')
174
//     done()
175
//   })
176
// })
177
178
 describe('unit tests', function () {
179
   describe('helpers.js', function () {
180
     describe('findCode', function () {
181
       for (let i = 0; i < fencedCodeTests.length; i++) {
182
         it(fencedCodeTests[i].name, function () {
183
           let r = findCode(fencedCodeTests[i].text)
184
           delete r.info
185
           assert.deepEqual(r, fencedCodeTests[i].result)
186
         })
187
       }
188
     })
189
     describe('findMdpInsertBlocks', function () {
190
       for (let i = 0; i < mdpLinkTests.length; i++) {
191
         it(mdpLinkTests[i].name, function () {
192
           let r = findMdpInsert(mdpLinkTests[i].text)
193
           delete r.info
194
           assert.deepEqual(r, mdpLinkTests[i].result)
195
         })
196
       }
197
     })
198
     describe('findMdpCode', function () {
199
       for (let i = 0; i < mdpCodeTests.length; i++) {
200
         it(mdpCodeTests[i].name, function () {
201
           let r = findMdpCode(mdpCodeTests[i].text)
202
           delete r.info
203
           assert.deepEqual(r, mdpCodeTests[i].result)
204
         })
205
       }
206
     })
207
     describe('runCliCmd', function () {
208
       it('Simple', function () {
209
         assert.equal(runCliCmd('cat abc.txt', 'test/docs').toString(), 'abc')
210
       })
211
       it('invalid', function () {
212
         if (os.platform() === 'win32') {
213
           assert.equal(runCliCmd('catt abc.txt', 'test/docs').toString(), 'ERROR: Command failed: catt abc.txt\n\'catt\' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n')
214
         } else {
215
           assert.equal(runCliCmd('catt abc.txt', 'test/docs').toString(), 'ERROR: Command failed: catt abc.txt\n/bin/sh: 1: catt: not found\n')
216
         }
217
       })
218
     })
219
     describe('processText', function () {
220
       for (let i = 0; i < processTextTests.length; i++) {
221
         it(processTextTests[i].name + ' --clear', function () {
222
           let r = processText(processTextTests[i].text, true, process.cwd())
223
           assert.equal(r, processTextTests[i].clear)
224
         })
225
         it(processTextTests[i].name + ' full', function () {
226
           let r = processText(processTextTests[i].text, false, process.cwd())
227
           if (os.platform() === 'win32') {
228
             assert.equal(r, processTextTests[i].full_win)
229
           } else {
230
             assert.equal(r, processTextTests[i].full_linux)
231
           }
232
         })
233
       }
234
     })
235
     describe('processFile.js', function () {
236
       it('reference to processFile.js OK', function () {
237
         assert(processFile)
238
       })
239
       it('process file against missing file should error', function () {
240
         assert.throws(function () { processFile('not a file') }, /file not found/)
241
       })
242
     })
243
   })
244
 })
245
246
 describe('mdprepare', function () {
247
   it('fires and returns "processed x files message (1)"', function (done) {
248
     this.timeout(8000)
249
     exec('mdprepare --ignore=**/*.md', function (error, stdout, stderr) {
0 ignored issues
show
Unused Code introduced by
The parameter stderr is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
250
       assert.ifError(error)
251
       assert.notEqual(stdout.toString().indexOf('processed 0 files'), -1)
252
       done()
253
     })
254
   })
255
256
   it('fires and returns "processed x files message (2)"', function (done) {
257
     this.timeout(8000)
258
     exec('mdprepare fred', function (error, stdout, stderr) {
0 ignored issues
show
Unused Code introduced by
The parameter stderr is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
259
       assert.ifError(error)
260
       assert.notEqual(stdout.toString().indexOf('processed 0 files'), -1)
261
       done()
262
     })
263
   })
264
265
   it('fires and returns error if directory not found', function (done) {
266
     this.timeout(8000)
267
     exec('mdprepare //', function (error, stdout, stderr) {
268
       assert.ifError(error)
269
       assert.notEqual(stderr.toString(), '')
270
       done()
271
     })
272
   })
273
 })
274
275
 describe('mdprepare test files', function () {
276
   fs.emptyDirSync('./test/preparedClear')
277
   fs.copySync('./test/docs', './test/preparedClear')
278
   fs.emptyDirSync('./test/preparedFull')
279
   fs.copySync('./test/docs', './test/preparedFull')
280
   var files = fs.readdirSync('./test/docs')
281
   for (let i = 0; i < files.length; i++) {
282
     if (files[i].substr(-3) === '.md') {
283
       it('/test/docs/' + files[i] + ' is prepared correctly', function (done) {
284
         this.timeout(8000)
285
         exec('mdprepare ./test/preparedFull/' + files[i], function (error, stdout, stderr) {
0 ignored issues
show
Unused Code introduced by
The parameter stdout is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter stderr is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
286
           assert.ifError(error)
287
           assert.equal(fs.readFileSync('./test/preparedFull/' + files[i], 'utf8'), fs.readFileSync('./test/preparedFull/' + files[i] + '.full', 'utf8'))
288
           done()
289
         })
290
       })
291
       it('/test/docs/' + files[i] + ' is cleared correctly', function (done) {
292
         this.timeout(8000)
293
         exec('mdprepare ./test/preparedClear/' + files[i] + ' --clear', function (error, stdout, stderr) {
0 ignored issues
show
Unused Code introduced by
The parameter stderr is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter stdout is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
294
           assert.ifError(error)
295
           assert.equal(fs.readFileSync('./test/preparedClear/' + files[i], 'utf8'), fs.readFileSync('./test/preparedClear/' + files[i] + '.clear', 'utf8'))
296
           done()
297
         })
298
       })
299
     }
300
   }
301
   it('test working with read only file - should error', function (done) {
302
     this.timeout(8000)
303
     fs.writeFileSync('./test/preparedClear/readonly.md', '[>]: # (mdpInsert cat test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n')
304
     fs.chmodSync('./test/preparedClear/readonly.md', 0o444) // make file read only
305
     exec('mdprepare ./test/preparedClear/readonly.md', function (error, stdout, stderr) {
306
       assert.ifError(error)
307
       assert.notEqual(stderr.toString(), '')
308
       done()
309
     })
310
   })
311
 })
312